package com.example.basicdemo.model.result;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.example.basicdemo.model.domain.SysUserLDAPDomain;
import com.example.basicdemo.model.response.OsLoginStatusResponse;
import com.isyscore.os.dev.api.IsyscoreResult;
import com.isyscore.os.dev.util.StringUtils;

import java.util.List;

public class OsLoginStatusResult implements IsyscoreResult<SysUserLDAPDomain> {

    private OsLoginStatusResponse response;

    public OsLoginStatusResult(OsLoginStatusResponse response) {
        this.response = response;
    }

    public OsLoginStatusResponse getResponse() {
        return response;
    }

    public void setResponse(OsLoginStatusResponse response) {
        this.response = response;
    }

    @Override
    public boolean isSuccess() {
        return response == null ? false : response.isSuccess();
    }

    @Override
    public SysUserLDAPDomain parseData() {
        if (this.isSuccess()) {
            String body = response.getBody();
            if (!StringUtils.isEmpty(body)) {
                return JSON.parseObject(body, new TypeReference<SysUserLDAPDomain>() {
                });
            }
        }
        return null;
    }

    @Override
    public List<SysUserLDAPDomain> parseListData() {
        return null;
    }
}
